package nadav.tasher.lightool.graphics.view.appview.corner;

import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.StackLayout;
import ohos.agp.utils.LayoutAlignment;
import ohos.app.Context;

public class CornerView extends StackLayout {
    private DirectionalLayout topLeft, topRight, bottomLeft, bottomRight;

    public CornerView(Context context) {
        super(context);
        init();
    }

    private void init(){
        // Init Views
        topLeft=new DirectionalLayout(getContext());
        topRight=new DirectionalLayout(getContext());
        bottomLeft=new DirectionalLayout(getContext());
        bottomRight=new DirectionalLayout(getContext());

        // Set LayoutDirection
        topLeft.setLayoutDirection(LayoutDirection.LTR);
        topRight.setLayoutDirection(LayoutDirection.LTR);
        bottomLeft.setLayoutDirection(LayoutDirection.LTR);
        bottomRight.setLayoutDirection(LayoutDirection.LTR);
        // Set Orientation
        topLeft.setOrientation(Component.VERTICAL);
        topRight.setOrientation(Component.VERTICAL);
        bottomLeft.setOrientation(Component.VERTICAL);
        bottomRight.setOrientation(Component.VERTICAL);
        // Set Gravity
        topLeft.setAlignment(LayoutAlignment.TOP | LayoutAlignment.START);
        topRight.setAlignment(LayoutAlignment.TOP | LayoutAlignment.END);
        bottomLeft.setAlignment(LayoutAlignment.BOTTOM | LayoutAlignment.START);
        bottomRight.setAlignment(LayoutAlignment.BOTTOM | LayoutAlignment.END);
        // Set Size
        DirectionalLayout.LayoutConfig parameters = new DirectionalLayout.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT,ComponentContainer.LayoutConfig.MATCH_PARENT);
        topLeft.setLayoutConfig(parameters);
        topRight.setLayoutConfig(parameters);
        bottomLeft.setLayoutConfig(parameters);
        bottomRight.setLayoutConfig(parameters);

        setLayoutConfig(new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_PARENT));

        addComponent(topLeft);
        addComponent(topRight);
        addComponent(bottomLeft);
        addComponent(bottomRight);
    }

    public void setTopLeft(Corner s) {
        if (s == null) {
            topLeft.removeAllComponents();
        } else {
            s.setLocation(Corner.TOP_LEFT);
            topLeft.removeAllComponents();
            topLeft.addComponent(s);
        }
    }

    public void setTopRight(Corner s) {
        if (s == null) {
            topRight.removeAllComponents();
        } else {
            s.setLocation(Corner.TOP_RIGHT);
            topRight.removeAllComponents();
            topRight.addComponent(s);
        }
    }

    public void setBottomLeft(Corner s) {
        if (s == null) {
            bottomLeft.removeAllComponents();
        } else {
            s.setLocation(Corner.BOTTOM_LEFT);
            bottomLeft.removeAllComponents();
            bottomLeft.addComponent(s);
        }
    }

    public void setBottomRight(Corner s) {
        if (s == null) {
            bottomRight.removeAllComponents();
        } else {
            s.setLocation(Corner.BOTTOM_RIGHT);
            bottomRight.removeAllComponents();
            bottomRight.addComponent(s);
        }
    }
}
